package hu;

import java.util.*;

public class hu43 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] maxi = new int[m][n];
        int[][] used = new int[m][n];
        sc.nextLine();
        for (int i = 0; i < m; i++) {
            String[] s = sc.nextLine().split(" ");
            for (int j = 0; j < n; j++) {
                maxi[i][j] = Integer.parseInt(s[j]);
            }
        }
        int p = 0, q = 0;
        List<List<Integer>> path = new ArrayList<>();
        List<List<Integer>> best_path = new ArrayList<>();
        bfs(p, q, m, n, path, best_path, maxi, used);
        for(List l : best_path){
            System.out.println("(" + l.get(0) + "," + l.get(1) + ")");
        }

    }


    public static void bfs(int p, int q, int m, int n, List<List<Integer>> path,
                           List<List<Integer>> best_path, int[][] maxi, int[][] used){
        if(p >= m || q >= n || p < 0 || q < 0 || maxi[p][q] == 1 || used[p][q] == 1)
            return;

        List<Integer> node = new ArrayList<>();
        node.add(p);
        node.add(q);
        path.add(node);
        used[p][q] = 1;

        if(p == m - 1 && q == n - 1){
            if(best_path.isEmpty() || path.size() < best_path.size()){
                best_path.clear();
                for(List l : path)
                    best_path.add(l);
            }
        }
        bfs(p - 1, q, m, n, path, best_path, maxi, used);
        bfs(p, q - 1, m, n, path, best_path, maxi, used);
        bfs(p + 1, q, m, n, path, best_path, maxi, used);
        bfs(p, q + 1, m, n, path, best_path, maxi, used);
        path.remove(path.size() - 1);
        used[p][q] = 0;
    }
}
